package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: sky-take-out
 * @BelongsPackage: com.sky.controller.user
 * @Author: song
 * @CreateTime: 2024-01-15  16:00
 * @Description: 购物车相关接口Controller
 * @Version: 1.0
 */

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端-购物车接口")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;
    /**
     * @description:C端-添加购物车
     * @author: song
     * @date: 2024/1/15 16:06
     * @param: [shoppingCartDTO]
     * @return: com.sky.result.Result
     **/
    @PostMapping("/add")
    @ApiOperation("C端-添加购物车")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车的信息，{}",shoppingCartDTO);
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    /**
     * @description:查看购物车
     * @author: song
     * @date: 2024/1/15 16:47
     * @param: []
     * @return: com.sky.result.Result<java.util.List<com.sky.entity.ShoppingCart>>
     **/
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> list(){
        return Result.success(shoppingCartService.showShoppingCart());
    }
    /**
     * @description:清空购物车
     * @author: song
     * @date: 2024/1/15 16:56
     * @param: []
     * @return: com.sky.result.Result<java.lang.String>
     **/
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result<String> deleteShoppingCart(){
        shoppingCartService.deleteShoppingCart();
        return Result.success("已全部清空！");
    }
}
